﻿using System;
using System.Collections.Generic;

namespace Tuxedo.Compile
{
	internal class FPEnum : IRootEntity
	{
		public FPEnum(string namespacePrefix, string name, Dictionary<string, int> values)
		{

		}

		public string FullyQualifiedName { get { throw new Exception(); } }

		public static FPEnum ParseEnum(string namespacePrefix, TokenStream tokens)
		{
			string name = tokens.PopIdentifier();
			tokens.PopExpected("{");

			Dictionary<string, int> values = new Dictionary<string, int>();

			int counter = 0;
			while (!tokens.IsNext("}"))
			{
				string enumValue = tokens.PopIdentifier();
				if (tokens.PopIfPresent("="))
				{
					Expression expression = Expression.ParseExpression(tokens);
					// nope. this won't work. Save the complex expression and resolve in a 2nd pass
					counter = 42; //  expression.ResolveIntegerValue();
				}
				
				values.Add(enumValue, counter++);

				if (!tokens.PopIfPresent(","))
				{
					break;
				}
			}
			tokens.PopExpected("}");

			return new FPEnum(namespacePrefix, name, values);
		}
	}
}
